//
//  BSDIYHeader.m
//  BaiSiBuDeJie
//
//  Created by chaoyi on 16/8/25.
//  Copyright © 2016年 tsaievan. All rights reserved.
//

#import "BSDIYHeader.h"

@interface BSDIYHeader ()

@property (nonatomic,weak)UILabel *textLab;

@property (nonatomic,weak)UIImageView *imgView;

@property (nonatomic,weak)UIActivityIndicatorView *juHuaView;
@end

@implementation BSDIYHeader

- (void)prepare{
    
    [super prepare];
    
    self.backgroundColor = [UIColor colorWithRed:0.95 green:0.95 blue:0.95 alpha:1.00];
    
    UILabel *textLab = [[UILabel alloc]init];
    [self addSubview:textLab];
    self.textLab = textLab;
    textLab.text = @"下拉刷新";
    textLab.textAlignment = NSTextAlignmentCenter;
    textLab.font = [UIFont fontWithName:@"AmericanTypewriter-Bold" size:14];
    
    UIImageView *imgView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"Snip20160828_8"]];
    [self addSubview:imgView];
    self.imgView =imgView;

    
    UIActivityIndicatorView *juHuaView = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
    [self addSubview:juHuaView];
    self.juHuaView = juHuaView;
    juHuaView.hidden = YES;
    
}
- (void)placeSubviews
{
    [super placeSubviews];
    
    self.textLab.mj_w = self.mj_w;
    self.textLab.mj_h = 20;
    self.textLab.mj_x = 0;
    self.textLab.mj_y = 12;
    
    
    self.imgView.mj_w = 16;
    self.imgView.mj_h =37;
    self.imgView.mj_x = 30;
    self.imgView.mj_y = (self.mj_h - self.imgView.mj_h)/2;
    
    
    self.juHuaView.mj_h = 20;
    self.juHuaView.mj_w = 20;
    self.juHuaView.mj_x =30;
    self.juHuaView.mj_y = (self.mj_h - self.juHuaView.mj_h)/2-5;
    
}

#pragma mark 监听控件的刷新状态
- (void)setState:(MJRefreshState)state
{
    
    MJRefreshCheckState;
    switch (state) {
        case MJRefreshStateIdle: {

            break;
        }
        case MJRefreshStatePulling: {

            break;
        }
        case MJRefreshStateRefreshing: {
            self.textLab.text = @"加载中...";
            self.imgView.hidden = YES;
            self.juHuaView.hidden = NO;
            [self.juHuaView startAnimating];

            break;
        }
        default: {
            
            break;
        }
    }
    
    
}

- (void)setPullingPercent:(CGFloat)pullingPercent
{
    [super setPullingPercent:pullingPercent];
    
    switch (self.state) {
        case MJRefreshStateIdle: {
 

            break;
        }
        case MJRefreshStatePulling: {

            break;
        }
        case MJRefreshStateRefreshing: {

        }
        case MJRefreshStateWillRefresh: {
            self.textLab.text = @"加载中...";
            self.imgView.hidden = YES;
            self.juHuaView.hidden = NO;
            [self.juHuaView startAnimating];
            break;
            
            break;
        }
        case MJRefreshStateNoMoreData: {
            
            break;
        }
    }
}


#pragma mark 监听scrollView的contentOffset改变
- (void)scrollViewContentOffsetDidChange:(NSDictionary *)change
{
    [super scrollViewContentOffsetDidChange:change];
    
}

#pragma mark 监听scrollView的contentSize改变
- (void)scrollViewContentSizeDidChange:(NSDictionary *)change
{
    [super scrollViewContentSizeDidChange:change];
    
}

#pragma mark 监听scrollView的状态改变
- (void)scrollViewPanStateDidChange:(NSDictionary *)change{
    
    if (self.state == MJRefreshStateRefreshing) {

    }
    if(self.state ==  MJRefreshStatePulling){
        self.imgView.image = [UIImage imageNamed:@"Snip20160828_10"];
        self.textLab.text = @"松手立即更新";
    }
    if(self.state ==  MJRefreshStateIdle){
        
        
        self.imgView.hidden = NO;
        self.imgView.image = [UIImage imageNamed:@"Snip20160828_8"];
        self.textLab.text = @"下拉刷新";
        [self.juHuaView stopAnimating];
    }
    
    [super scrollViewPanStateDidChange:change];
    
}



@end
